package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Author: Rodgers
 * @Date 2022/3/20 10:32
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired(required = false)
    private OrderService orderService;

    //处理添加订单请求
    @RequestMapping("/submit")
    public R<String> submit(@RequestBody Orders orders, HttpSession session){
        //1.接收前端传递过来json数据封装到Orders对象中
        //2.获取登录的用户id
        Long  userId = (Long) session.getAttribute("user");

        //3.调用业务生成订单数据，传递Orders和用户id 传递过去
        orderService.addOrder(orders,userId);

        //4.封装数据返回
        return R.success("下单成功");
    }
}
